package com.zhengdongzulin.zuke.app.main.mine.lifeservice

import androidx.lifecycle.rxLifeScope
import com.lxj.androidktx.livedata.StateLiveData
import com.zhengdongzulin.zuke.app.Api
import com.zhengdongzulin.zuke.app.data.LifeServiceDetails
import com.zhengdongzulin.zuke.base.BaseViewModel
import rxhttp.wrapper.param.RxHttp
import rxhttp.wrapper.param.toResponse

class LifeServiceDetailsVm : BaseViewModel() {

    //保洁详情
    var get_clean_detail: StateLiveData<LifeServiceDetails> = StateLiveData()
    fun get_clean_detail(id: String) {
        rxLifeScope.launch(
            {
                var r = RxHttp.postJson(Api.GET_CLEAN_DETAIL)
                    .add("id", id)
                    .toResponse<LifeServiceDetails>()
                    .await()
                get_clean_detail.postValueAndSuccess(r)
            }, {
                assignment(it, get_clean_detail)
            }
        )
    }

    //维修详情
    var get_repair_detail: StateLiveData<LifeServiceDetails> = StateLiveData()
    fun get_repair_detail(id: String) {
        rxLifeScope.launch(
            {
                var r = RxHttp.postJson(Api.GET_REPAIR_DETAIL)
                    .add("id", id)
                    .toResponse<LifeServiceDetails>()
                    .await()
                get_repair_detail.postValueAndSuccess(r)
            }, {
                assignment(it, get_repair_detail)
            }
        )
    }

    //投诉详情
    var get_complaint_letter: StateLiveData<LifeServiceDetails> = StateLiveData()
    fun get_complaint_letter(id: String) {
        rxLifeScope.launch(
            {
                var r = RxHttp.postJson(Api.GET_COMPLAINT_LETTER)
                    .add("id", id)
                    .toResponse<LifeServiceDetails>()
                    .await()
                get_complaint_letter.postValueAndSuccess(r)
            }, {
                assignment(it, get_complaint_letter)
            }
        )
    }

}